package com.example.tbtx.tbtx.utils;

import android.content.Context;
import android.graphics.PixelFormat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.example.tbtx.tbtx.R;
import com.example.tbtx.tbtx.view.CloudProgressView;

public class MaskUtil {

    private static WindowManager windowManager;

    public MaskUtil(final Context context, final CloudProgressView.StartActivityCallBack callBack) {
        windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        params.gravity = Gravity.CENTER;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.format = PixelFormat.RGBA_8888;
        params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_FULLSCREEN;
        params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
        final RelativeLayout mask = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.activity_mask_common, null);
        windowManager.addView(mask, params);

        final RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//        mask.post(new Runnable() {
//            @Override
//            public void run() {
        CloudProgressView progressView = new CloudProgressView(context);
        progressView.setCallBack(callBack);
        mask.addView(progressView, layoutParams);
        progressView.startAnima(new CloudProgressView.AnimatorCallBack() {
            @Override
            public void animatorEnd() {
                windowManager.removeView(mask);
            }
        });
//            }
//        });
    }

}
